<?php

namespace App\Providers;

use App\Events\InstallApp;
use App\Events\OrderPaid;
use App\Listeners\CreateAdmin;
use App\Listeners\CreateData;
use App\Listeners\CreateDatabase;
use App\Listeners\InitApp;
use App\Listeners\MakeMigrate;
use App\Listeners\RemoveCartItem;
use App\Listeners\UpdateProductSoldCount;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],

        /*
         * 支付后事件:
         * 1. 更新商品的销量
         * 2. 清除相应的购物车数据
         * 3. 发送邮件通知
         * 4. 发送短信通知
         */
        OrderPaid::class => [
            UpdateProductSoldCount::class, // 更新商品的销量
            RemoveCartItem::class
        ],

        /**
         * 安装项目事件
         * 1. 生成项目key, 缓存route ...
         * 2. 创建数据库
         * 3. 执行数据迁移 (同时判断是否需要生成伪造数据)
         * 4. 导入表的关键数据 (后台用户名密码, 后台菜单, 后台权限关系 ...)
         */
        InstallApp::class => [
            InitApp::class,
            CreateDatabase::class,
            CreateData::class,
            CreateAdmin::class
        ]
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
    }
}
